export interface LighthouseConfig {
  serverEndPoint: string;
  params: {
    cookies: any[];
    webUrl: string;
    [key: string]: any;
  };
  onSuccess?: (result: any) => void;
  onError?: (error: any) => void;
}

export class LighthouseSDK {
  private config: LighthouseConfig;

  constructor(config: LighthouseConfig) {
    this.config = config;
  }

  async performTest(): Promise<void> {
    try {
      const response = await fetch(this.config.serverEndPoint, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ ...this.config.params }),
      });

      const result = await response.json();
      if (this.config.onSuccess) {
        this.config.onSuccess(result);
      } else {
        console.log("Performance test result: ", result);
      }
    } catch (error) {
      if (this.config.onError) {
        this.config.onError(error as Error);
      } else {
        console.error("Error performing performance test: ", error);
      }
    }
  }
}
